package com.wyh.controlller;

import com.wyh.dao.ThreeLevDao;
import com.wyh.entity.ThreeLev;
import com.wyh.service.ThreeLevService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import java.util.List;

/**
 * @Author wangyaohan
 * @Date 2021/9/25 9:09
 * @ClassName ThreeLevController
 */
@RestController
@RequestMapping("thl")
@CrossOrigin
public class ThreeLevController {

    @Resource
    private ThreeLevDao threeLevDao;
    @Autowired
    private ThreeLevService threeLevService;

    @RequestMapping("find")
    public Object find(@RequestParam(value = "id", defaultValue = "0") Integer id) {
        List<ThreeLev> list = threeLevDao.findByPid(id);
        list.forEach(item -> {
            List<ThreeLev> s = threeLevDao.findByPid(item.getId());
            s.forEach(ss -> {
                ss.setChildren(threeLevDao.findByPid(ss.getId()));
            });
            item.setChildren(s);
        });
        return list;

    }
}
